import { getOrderDetail,comfirmOrder } from '../../../../../common/api/index'
Page({
    data: {
		orderInfo:{},
    },
    onLoad(options) {
		if(options.id){
			this.setData({
				orderId: options.id
			})
			this.getOrderInfos()
		}
	},
	getOrderInfos(){
		getOrderDetail(this.data.orderId).then(res => {
			if(res.code == 200){
				if(res.data.orderStatus == 1){
					res.data.statusName = '未付款'
				}
				if(res.data.orderStatus == 2 || res.data.orderStatus == 11){
					res.data.statusName = '待发货'
				}
				if(res.data.orderStatus == 3){
					res.data.statusName = '已发货'
				}
				if(res.data.orderStatus == 4){
					res.data.statusName = '已收货'
				}
				if(res.data.orderStatus == 5 || res.data.orderStatus == 6){
					res.data.statusName = '售后'
				}
				if(res.data.payMethod == 'remit'){
					res.data.payMethodName = '打款支付'
				}
				if(res.data.payMethod == 'wechat'){
					res.data.payMethodName = '微信支付'
				}
				if(res.data.payMethod == 'balance'){
					res.data.payMethodName = '余额支付'
				}
				this.setData({
					orderInfo: res.data
				})
			}
		})
	},
	// 未支付订单  ----- 立即支付
	toPayOrder(e){
		let data = e.currentTarget.dataset.item;
		let ids = [];
		data.details.forEach(item => {
			ids.push(item.productId)
		})
		if(ids.length > 0){
			ids = ids.join(',')
			let path = '/pages/component/classify/pay/index?orderId='+data.orderId+'&productIds='+ids+"&totalMoney="+ data.payAmount
			wx.$goTo(path,true)
		}
	},
	// 确认收获
	toComfirmOrder(e){
		let that = this
		wx.showModal({
			title: '提示',
			content: '是否确认收货？',
			success (res) {
			  if (res.confirm) {
				let info = e.currentTarget.dataset.item;
				comfirmOrder(info.orderId).then(res => {
					if(res.code == 200){
						wx.showToast({
							title: '收货成功！',
							icon: 'success',
							duration: 2000
						})
						that.getOrderInfos()
					}
				})
			  }
			}
		})
	},
})